/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase - JoinTest
 * <p>Powered by webrx On 2021-12-27 15:22:55
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class JoinTest {
    void work() {
        String tn = Thread.currentThread().getName();
        System.out.println(tn + "启动");
        for (int i = 0; i < 3; i++) {
            try {
                TimeUnit.SECONDS.sleep(2);
                if ("T2".equals(tn))
                    TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(tn + ":" + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        var t = new JoinTest();
        var t1 = new Thread(t::work, "T1");
        var t2 = new Thread(t::work, "T2");
        var t3 = new Thread(t::work, "T3");

        t1.start();
        t1.join();


        t2.start();
        t3.start();
        t3.join();


        String tn = Thread.currentThread().getName();
        System.out.println(tn + "启动");
        for (int i = 0; i < 3; i++) {

            System.out.println(tn + ":" + i);
        }
    }
}
